const Mongoose = require("./db");
const notice = require("../counts/notice.js");
const formatDateHelper = require('../utils/formatDateHelper.js')
const noticeSchema = new Mongoose.Schema({
	id: {
		type: Number,
		unique: true,
	},
	title: String,
	start_date: String,
	content: String,
	create: {
		type: String,
		default: formatDateHelper.date() 
	},
	modify: {
		type: String,
		default: formatDateHelper.date()
	}
})


noticeSchema.pre("save", async function(next) {
	const self = this;
	try {
		if (!self.id) {
			self.id = await notice.getNextSequenceValue("id");
		}
	} catch (err) {
		next(err);
	}
});

const noticeModel = Mongoose.model("notices", noticeSchema);

module.exports = noticeModel;